package com.tj.jinzao.fragment;

import android.content.Intent;
import android.os.Bundle;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;

import com.tj.jinzao.R;
import com.tj.jinzao.activity.ExchangeRecordDetailActivity;
import com.tj.jinzao.adapter.ExchangeRecordListItemAdapter;
import com.tj.jinzao.base.BaseDataListFragment;
import com.tj.jinzao.base.IBaseView;
import com.tj.jinzao.model.ExchangeRecord;
import com.tj.jinzao.presenter.ExchangeRecordPresenter;
import com.tj.jinzao.widgets.EmptyView;

import java.util.List;

/**
 * 健康报告列表fragment
 * Created by wjy on 2019/1/1.
 */
public class ExchangeRecordListFragment extends BaseDataListFragment<List<ExchangeRecord>, ExchangeRecordPresenter, ExchangeRecord> implements IBaseView<List<ExchangeRecord>> {

    public static ExchangeRecordListFragment newInstance() {
        ExchangeRecordListFragment fragment = new ExchangeRecordListFragment();
        if (fragment != null) {
            Bundle args = new Bundle(3);
            args.putString(ARG_TAG_ID, String.valueOf(1));
            args.putInt(ARG_LOAD_ID, 1);
            args.putInt(ARG_LAYOUT_RES_ID, R.layout.base_fragment_item_layout);
            fragment.setArguments(args);
        }
        return fragment;
    }

    @Override
    public void onRequestNoData(String message) {
        setEmptyDataView();
    }

    @Override
    protected ExchangeRecordPresenter createPresenter() {
        return new ExchangeRecordPresenter(this);
    }


    @Override
    protected void createView(LayoutInflater inflater, View view) {

    }

    @Override
    protected RecyclerView.Adapter createAdapter() {
        return new ExchangeRecordListItemAdapter(mContext, mData);
    }

    @Override
    protected void requestData() {
        mPresenter.getExchangeRecord();
    }

    @Override
    protected void setEmptyDataView() {
        mEmptyView.setVisibility(View.VISIBLE);
        mEmptyView.setState(EmptyView.State.NO_DATA, "没有内容哦");
    }

    @Override
    protected boolean resolveData(List<ExchangeRecord> exchangeRecords) {
        return false;
    }

    @Override
    protected boolean canLoadMoreItems() {
        return false;
    }

    @Override
    public void onRequestSuccess(List<ExchangeRecord> list) {
        super.onRequestSuccess(list);
        if (mPageNo <= 1) {
            mData.clear();
        }
        mData.addAll(list);
        showListView();

    }

    @Override
    protected void initData() {
    }

    @Override
    protected void itemClicked(int position, ExchangeRecord data) {
        startActivity(new Intent(mContext, ExchangeRecordDetailActivity.class).putExtra("record",data));
    }

}
